/*
*****************************************************************************
*                  Political Cycle and GDP Manipulation                     *
*                                  Master                                   *
*****************************************************************************
 File Name: Master.do
 Description:  This program records all of the programs that need to be run of this paper.
 Created on:  August 2024
 Last Modified: February 6, 2025
*/

clear all
set more off, permanent

/*Before running code, set the path first */
cd "Set your path here"             /*like D:\Working\*/
use "MasterData.dta"    
*****************************************************************************
*                            Descriptive Statistics                         *
*****************************************************************************
**Check if the random effects follow a normal distribution
mixed cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear  Industry3 population_density dn || provinceid: Rank market fiscal_autonomy Provincial_Secretary || citycode:, reml
// Predict the random effects
predict re_rank re_market re_autonomy re_secretary re_province re_city, reffects
*re_market
// Plot a histogram
histogram re_market
// Plot a quantile-quantile (QQ) plot
qnorm re_market
// Perform a Shapiro-Wilk test
swilk re_market
*re_autonomy
// Plot a histogram
histogram re_autonomy
// Plot a quantile-quantile (QQ) plot
qnorm re_autonomy
// Perform a Shapiro-Wilk test
swilk re_autonomy

// Check skewness and kurtosis
summarize re_autonomy re_market, detail
sum cheating_gdp
hist cheating_gdp
**Table 1 Descriptive Statistics
tabstat ln_gdp lntrue_gdp cheating_gdp quarter4 market fiscal_autonomy Provincial_Secretary target_city rank_gdpr_3q Industry3 mayor_age secretary_age mayor_lastyear secretary_lastyear Rank  population_density  urbanization,s( mean sd min max) c(s) f(%10.2f)	

*****************************************************************************
*                              Baseline Regression                          *
*****************************************************************************

**Table 2 The Impact of Political Cycle on GDP Manipulation: ML/FE(r)/TWFE/GMM
*Model（1） ML（no controls）
mixed cheating_gdp quarter4 || provinceid: || citycode:, reml
eststo maincheating
*Model（2） ML（with controls）
mixed cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age Rank  mayor_lastyear secretary_lastyear Industry3 urbanization  population_density  || provinceid: || citycode:, reml 
eststo controls14
*Model（3） FE(r) 
xtreg cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3  population_density  ,fe   
eststo FE
xtreg cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3  population_density  ,re 
eststo RE
hausman FE RE
xtreg cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3  population_density  i.year ,fe  
testparm i.year   
xtreg cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3  population_density  ,fe 
xttest3 //Presence of heteroskedasticity
xtserial cheating_gdp quarter4 //no autocorrelation

xtreg cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 urbanization population_density  ,fe r
eststo fer2
*Model（4）TWFE
xtreg cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 urbanization population_density  i.year ,fe 
 eststo towwfe2
*Model（5）GMM
xtabond cheating_gdp L.cheating_gdp quarter4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 urbanization population_density , lags(1) robust
eststo gmm22
esttab  maincheating controls14 fer2 towwfe2 gmm22 using 130baseline.rtf, ///
    append star(* 0.10 ** 0.05 *** 0.01) staraux r2 nogaps ///
     mtitles((ML) (ML) (FE(r)) (TWFE) (GMM)) ///
    title("Table 2 Baseline Regression") ///
    b(%9.3f) se(%9.3f) ///
    cells(b(star fmt(%9.3f)) se(fmt(%9.3f) par([ ])))	
	
*****************************************************************************
*                             Heterogeneous Effect                          *
*****************************************************************************
**Table3 Moderating Influences：Organizational Slack

** Model（1）Interaction term: Municipal_fiscal(municipal)
mixed cheating_gdp i.quarter4##c.Municipal_fiscal target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density   || provinceid: || citycode:, reml
eststo mfiscal142
** Model（2）Interaction term: fiscal_autonomy(provincial)
mixed cheating_gdp i.quarter4##c.fiscal_autonomy target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
eststo fiscal142	
esttab  mfiscal142 fiscal142  using moderator0201.rtf, ///
    append star(* 0.10 ** 0.05 *** 0.01) staraux r2 nogaps ///
    title("Table 3 Moderating Influences of  Fiscal Autonomy") ///
    b(%9.3f) se(%9.3f) ///
    cells(b(star fmt(%9.3f)) se(fmt(%9.3f) par([ ])))
	
**Table 4 Moderating Influences：Marketization
* Model（1）Interaction term: market(overall impact of marketization)
mixed cheating_gdp i.quarter4##c.market target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
eststo marketme142	
* Model（2）Interaction term: market1(Government and Market Relationship)
mixed cheating_gdp i.quarter4##c.market1 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
eststo market222	
* Model（3）Interaction term: market2(Development of Non-State-Owned Economy)
mixed cheating_gdp i.quarter4##c.market2 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
eststo market232	
* Model（4）Interaction term: market3(Development Level of Product Market)
mixed cheating_gdp i.quarter4##c.market3 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
eststo market242	
* Model（5）Interaction term: market4(Development Level of Factor Market)
mixed cheating_gdp i.quarter4##c.market4 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
eststo market252
* Model（6）Interaction term: market5(Development of Market Intermediaries and Legal Framework)	
mixed cheating_gdp i.quarter4##c.market5 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
eststo market262	
esttab marketme142 market222 market232 market242 market252 market262 using moderator0201.rtf, ///
    append star(* 0.10 ** 0.05 *** 0.01) staraux r2 nogaps ///
     title("Table 4 Moderating Influences of Marketization") ///
    b(%9.3f) se(%9.3f) ///
    cells(b(star fmt(%9.3f)) se(fmt(%9.3f) par([ ])))	
	
***Figure 1 Marginal Effects plot for interaction term
**Figure 1.1 Interaction term: fiscal_autonomy
* 1. Run mixed-effects model
mixed cheating_gdp i.quarter4##c.fiscal_autonomy target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
* 2. Calculate marginal effects
margins, dydx(quarter4) at(fiscal_autonomy=(0(0.1)1)) 
* 3. Generate marginal effects plot
marginsplot, ///
    title("Conditional on Fiscal Autonomy", size(medium)) ///
    ytitle("Marginal Effect of Q4") ///
    xtitle("Fiscal Autonomy") ///
    xlabel(0(0.1)1) ///
    ylabel(, angle(horizontal)) ///
    plot1opts(lcolor(navy) lwidth(medthick)) ///
    ci1opts(lpattern(dash) lcolor(navy%50)) ///
    yline(0, lpattern(dash) lcolor(gray)) 
* 4. Optional: save the graph
graph save q4_marginal_effects.gph, replace

****Figure 1.1 Interaction term: market 
* 1. Run mixed-effects model
mixed cheating_gdp i.quarter4##c.market target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3 population_density  || provinceid: || citycode:, reml
* 2. Calculate marginal effects
margins, dydx(quarter4) at(market=(0(1)10))
* 3. Generate marginal effects plot
marginsplot, ///
    title("Conditional on Marketization Index", size(medium)) ///
    ytitle("Marginal Effect of Q4") ///
    xtitle("Marketization Index") ///
    xlabel(0(1)10) ///
    ylabel(, angle(horizontal)) ///
    plot1opts(lcolor(navy) lwidth(medthick)) ///
    ci1opts(lpattern(dash) lcolor(navy%50)) ///
    yline(0, lpattern(dash) lcolor(gray))    
* 4. Optional: save the graph
graph save q4_market_effects.gph, replace

** Graph Combine
graph use q4_marginal_effects.gph
graph use q4_market_effects.gph
graph combine q4_marginal_effects.gph q4_market_effects.gph, ///
    title("Marginal Effects of Fourth Quarter on GDP Manipulation") ///
    b1("Marginal Effects")  xsize(12) ysize(8)
graph export "combined_graphs.png", replace width(3000) as(png)
	
*****************************************************************************
*                           Strategic Manipulation                          *
*****************************************************************************   
**Table 5 Strategic Manipulation
*(1) officials' promotion incentives（FinalTerm）：Interaction with Provincial_Secretary (indicator for proximity to retirement, age 65 as cutoff)
* 1.Create a new variable to store the year of the next Provincial Party Congress, defaulting to 2017 (most provinces); some held it in 2016
gen next_party_congress_year = 2017
* 2.Replace the year with 2016 for provinces that held their Party Congress in 2016
replace next_party_congress_year = 2016 if inlist(provinceid, ///
    340000, 350000, 130000, 140000, 150000, 420000, 430000, 320000, 360000, 220000, 410000, 610000, 450000, 650000, 540000, 530000)
* 3.Calculate the Provincial Party Secretary's age at the time of the next Provincial Party Congress
label var birthyear "The birth year of the Provincial Party Secretary"
gen age_ProvPartySec = next_party_congress_year - birthyear
* 4.Create an indicator variable for proximity to retirement
gen Provincial_Secretary = 0
replace Provincial_Secretary = 1 if age_ProvPartySec >= 64 //(1,557 real changes made)

mixed cheating_gdp i.quarter4##i.Provincial_Secretary target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank industry3 population_density dn || provinceid: || citycode:, reml
eststo PSecretary142
*(2) first quarter (Q1) 
mixed cheating_gdp quarter1 target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3  population_density|| provinceid: || citycode:, reml	
eststo quarter111
*(3) the variation in data distortion across quarters
mixed cheating_gdp i.quarter target_city rank_gdpr_3q mayor_age secretary_age mayor_lastyear secretary_lastyear Rank Industry3  population_density dn|| provinceid: || citycode:, reml	
eststo quarter043
esttab PSecretary142 quarter111 quarter043 using table5.rtf, ///
    append star(* 0.10 ** 0.05 *** 0.01) staraux r2 nogaps ///
     mtitles((Retirement_Proximity) (Quarter)) ///
    title("Table 5") ///
    b(%9.3f) se(%9.3f) ///
    cells(b(star fmt(%9.3f)) se(fmt(%9.3f) par([ ])))	


